
package com.grt192.spot.mechanism.WallHugger;

import com.grt192.core.Mechanism;
import com.grt192.event.component.DemoSwitchListener;
import com.grt192.spot.sensor.GRTDemoSwitch;
import com.sun.spot.resources.transducers.IIOPin;
import com.sun.spot.sensorboard.EDemoBoard;

/**
 * Tool to send 300usec pulses on button press.
 * @author gerberduffy
 */
public class PinPulser extends Mechanism implements DemoSwitchListener {
    
//    private GRTLogicRelay relay;
    private IIOPin dPin;
    
    private GRTDemoSwitch sw;   //Button press
    
    public PinPulser(int pin, GRTDemoSwitch sw){
        dPin = EDemoBoard.getInstance().getIOPins()[pin];
        dPin.setAsOutput(true);
        this.sw = sw;
        sw.addSwitchListener(this);
        setPrinting(true);
        
    }
    
    public void pulse(){
        dPin.setHigh();
        dPin.setLow();
//        relay.doCommand(GRTLogicRelay.HIGH);
//        relay.doCommand(GRTLogicRelay.LOW);  
    }

    public void switchPressed(GRTDemoSwitch source) {
        
    }

    public void switchReleased(GRTDemoSwitch source) {
        log("pulse");
        pulse();
    }
    
}
